/*
 * Name        : CouponHttpRequest.java
 * Classes     : CouponHttpRequest
 * Version     : 1.0
 * Date        : 2013-9-16
 *
 * Copyright 2013 CMCC.  All rights reserved.
 * This material, including documentation and any related computer
 * programs, is protected by copyright controlled by CMCC.  All
 * rights are reserved.  Copying, including reproducing, storing,
 * adapting or translating, any or all of this material requires the
 * prior written consent of CMCC.  This material also contains
 * confidential information which may not be disclosed to others
 * without the prior written consent of CMCC.
 */

package com.xgkj.diyiketang.http;

import com.xgkj.diyiketang.util.AppMetaData;
import com.xgkj.diyiketang.util.PalLog;

import org.apache.http.protocol.HTTP;

import java.io.UnsupportedEncodingException;


/**
 * Class Name  : CouponHttpRequest
 * Author      : Huang xiao qing
 * Date        : 13-9-13
 * Description : Base HTTP request for coupon business.
 */
public class CouponHttpRequest extends HttpRequest {
    
  
    private String mNodeData;
    private String mApiNo;
   
    /**
     * Constructor with request.
     */
    public CouponHttpRequest(int requestType) {
        this(requestType, null);
    }

    public CouponHttpRequest() {
        super();
        mResponse = new CouponHttpResponse();
        setHttpMethod(HttpMethodType.HTTP_METHOD_POST);
    }
    
    /**
     * Constructor with request type and HttpEngine.
     *
     * @param requestType 
     * @param httpEngine for send HTTP request.
     */
    public CouponHttpRequest(int requestType, HttpEngine httpEngine) {
        super(requestType, httpEngine);
        mResponse = new CouponHttpResponse();
        setHttpMethod(HttpMethodType.HTTP_METHOD_POST);
    }
    
    /**
     * Set the xml root node for HTTP entity data when uses 'POST' method. 
     * @param root The post xml node
     */
    public void setData(String root){
        mNodeData = root;
    }
    
    public void setApiNo(String apiNo){
    	mApiNo = apiNo;
    }
    
    private void composeRequestData(){
        try {
            if( mNodeData != null ){
               PalLog.d("CouponHttpRequest", "Send POST: " + mNodeData);

                setData( mNodeData.getBytes(HTTP.UTF_8)); 
            }
         } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
         }
    }
    
    @Override
    public void startRequest() {

        String url;
        url = AppMetaData.HOST_BASE_URL+mApiNo;
        PalLog.d("HttpRequest", "Send URL: " + url);

        setUrl(url);
        composeRequestData();

        super.startRequest();
    }
	
}
